import { assert, beforeAll, describe, test } from 'vitest';
import { CHECK_MODE, testCaseCheck } from '../common/testCommon';
import AdjacentOverloadCheckDSL from '../../../../src/checker/dsl/AdjacentOverloadSignatureDsl';
import path from 'path';
import { CheckEntry, Rule } from '../../../../src/Index';

let realPath: string = '';
let checkEntry: CheckEntry;

beforeAll(async () => {
    const rule: Rule = new Rule('');
    checkEntry = await testCaseCheck(
        './test/unittest/sample/AdjacentOverloadSignatruesDsl',
        rule,
        CHECK_MODE.FILE2CHECK,
        AdjacentOverloadCheckDSL,
        false,
        true
    );
    realPath = checkEntry.scene.getRealProjectDir();
});

describe('AdjacentOverloadSignatureDsl ETS Report Cases', () => {
    test('AdjacentOverloadSignatureReport1 should be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/Report/AdjacentOverloadSignatureReport1.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.isAbove(detectFileReport?.issues.length, 0, 'Should detect issues in AdjacentOverloadSignatureReport1.ets');
    });

    test('AdjacentOverloadSignatureReport2 should be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/Report/AdjacentOverloadSignatureReport2.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.isAbove(detectFileReport?.issues.length, 0, 'Should detect issues in AdjacentOverloadSignatureReport2.ets');
    });

    test('AdjacentOverloadSignatureReport3 should be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/Report/AdjacentOverloadSignatureReport3.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.isAbove(detectFileReport?.issues.length, 0, 'Should detect issues in AdjacentOverloadSignatureReport3.ets');
    });
});

describe('AdjacentOverloadSignatureDsl ETS NoReport Cases', () => {
    test('AdjacentOverloadSignatureNoReport1 should not be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/NoReport/AdjacentOverloadSignatureNoReport1.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, 0, 'Should not detect issues in AdjacentOverloadSignatureNoReport1.ets');
    });

    test('AdjacentOverloadSignatureNoReport2 should not be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/NoReport/AdjacentOverloadSignatureNoReport2.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, 0, 'Should not detect issues in AdjacentOverloadSignatureNoReport2.ets');
    });

    test('AdjacentOverloadSignatureNoReport3 should not be detected', () => {
        const detectFile: string = path.join(realPath, 'ets/NoReport/AdjacentOverloadSignatureNoReport3.ets');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, 0, 'Should not detect issues in AdjacentOverloadSignatureNoReport3.ets');
    });
});
